<?php
class PHZ_SuanXi
{
    /**
     * 息数改变类
     * @param $room_info
     * @param $user_id
     * @param $mode
     * @param $card_number
     * @param $db_connect
     * @return bool
     */
    public static function __xi( $room_info , $user_id , $mode , $card_number , $db_connect ){
        $card_info  = $db_connect->select('*')->from('tt_room_card')->where('uid = '. $user_id .' and jid = '. $room_info['room_js'] .' and rid=' . $room_info['room_id'] )->row();
        $huxi = 0;
        switch ( $mode ){
            case 'wei_and_jing':
                $huxi     = $card_number <= 10 ? 6 : 6;//之前已经畏了这个字；然后又摸到这个字了，为惊
                break;
            case 'mop_open_wei':
                $huxi     = $card_number <= 10 ? 3 : 3;//摸牌被弃，跑其他玩家已经畏了的牌，只做3胡息的叠加
                break;
            case 'mop_open_peng':
                $huxi     = $card_number <= 10 ? 5 : 6;//摸牌被弃，跑其他玩家已经碰了的牌，只做3胡息的叠加
                break;
            case 'mop_open_shou':
                $huxi     = $card_number <= 10 ? 6 : 9;//摸牌被弃，跑其他玩家手中3个
                break;
            case 'hand_xiapao':
                $huxi     = $card_number <= 10 ? 3 : 3;//手打字，跑其他玩家畏过的牌（注意这里只能叠加跑的息；因为畏的时候的息已经算过了）
                break;
            case 'hand_pao':
                $huxi     = $card_number <= 10 ? 6 : 9;//手打字，跑其他玩家手中3个
                break;
            case 'mop_wei':
                $huxi     = $card_number <= 10 ? 3 : 6;//摸牌畏牌；小3，大6
                break;
            case 'mop_ti':
                $huxi     = $card_number <= 10 ? 9 : 12;//摸牌提牌;小字9胡，大字12胡
                break;
            case 'qs_tipai':
                $huxi     = $card_number <= 10 ? 9 : 12;//起手提牌;小字9胡，大字12胡
                break;
            case 'peng':
                $huxi     = $card_number <= 10 ? 1 : 3;//碰牌，小字1胡息；大字3胡息
                break;
            case 'chi':
                $eat_card = explode("_", $card_number );
                //小1.2.3
                if( $eat_card[0] <= 3 && $eat_card[1] <= 3 && $eat_card[2] <= 3 ){
                    $huxi = 3;
                }
                //大1.2.3
                if( ($eat_card[0] >= 11 && $eat_card[0] <= 13) &&
                    ($eat_card[1] >= 11 && $eat_card[1] <= 13) &&
                    ($eat_card[2] >= 11 && $eat_card[2] <= 13)
                ){
                    $huxi = 6;
                }
                //小1.5.10
                if( ($eat_card[0] == 1 || $eat_card[1] == 1 || $eat_card[2] == 1)  &&
                    ($eat_card[0] == 5 || $eat_card[1] == 5 || $eat_card[2] == 5) &&
                    ($eat_card[0] == 10 || $eat_card[1] == 10 || $eat_card[2] == 10)
                ){
                    $huxi = 3;
                }
                //大1.5.10
                if( ($eat_card[0] == 11 || $eat_card[1] == 11 || $eat_card[2] == 11)  &&
                    ($eat_card[0] == 15 || $eat_card[1] == 15 || $eat_card[2] == 15) &&
                    ($eat_card[0] == 20 || $eat_card[1] == 20 || $eat_card[2] == 20)
                ){
                    $huxi = 6;
                }
                //小2.7.10
                if( ($eat_card[0] == 2 || $eat_card[1] == 2 || $eat_card[2] == 2)  &&
                    ($eat_card[0] == 7 || $eat_card[1] == 7 || $eat_card[2] == 7) &&
                    ($eat_card[0] == 10 || $eat_card[1] == 10 || $eat_card[2] == 10)
                ){
                    $huxi = 3;
                }
                //大2.7.10
                if( ($eat_card[0] == 12 || $eat_card[1] == 12 || $eat_card[2] == 12)  &&
                    ($eat_card[0] == 17 || $eat_card[1] == 17 || $eat_card[2] == 17) &&
                    ($eat_card[0] == 20 || $eat_card[1] == 20 || $eat_card[2] == 20)
                ){
                    $huxi = 6;
                }
                break;
        }
        $huxi = $huxi + $card_info['huxi'];
        $db_connect->update('tt_room_card')->cols(array('huxi'=> $huxi  ))->where('id=' . $card_info['id'] )->query();
        //给用户下发最新息数情况信息
        PM_d::__index( $room_info['room_id']  , $db_connect , $user_id );
        //返回
        return true;
    }
}